package game.games.rpg;

import java.awt.Point;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JOptionPane;

public class World extends AttributedObject
{
    private Map<String, Room>  rooms              = new HashMap<String, Room>();
    private String             currentRoom        = null;
    private Map<String, Point> lastPlayerPosition = new HashMap<String, Point>();
    
    private Player             player;
    
    public World()
    {
        player = new Player(50, 3);
    }
    
    public Map<String, Room> getRooms()
    {
        return rooms;
    }
    
    public Room getCurrentRoom()
    {
        Room room = null;
        if (currentRoom != null)
        {
            room = rooms.get(currentRoom);
            if (room != null)
            {
                if (room.getPlayer() == null)
                {
                    room.setPlayer(getPlayer());
                }
            }
        }
        return room;
    }
    
    public void setCurrentRoom(String name)
    {
        this.currentRoom = name;
    }
    
    public void selectRoom()
    {
        String room = (String) JOptionPane.showInputDialog(null, "Choose wisely padawan", "Customized Dialog", JOptionPane.PLAIN_MESSAGE, null, rooms.keySet().toArray(), null);
        if (room != null)
        {
            setCurrentRoom(room);
        }
    }
    
    public void addRoom(Room room)
    {
        String name = room.getName();
        rooms.put(name, room);
        lastPlayerPosition.put(name, room.getPlayerPosition());
    }
    
    public Player getPlayer()
    {
        return player;
    }
    
    public void setPlayer(Player player)
    {
        this.player = player;
    }
    
    public Point getLastPlayerPosition(String room)
    {
        return lastPlayerPosition.get(room);
    }
    
    public void setLastPlayerPosition(Point position)
    {
        lastPlayerPosition.put(currentRoom, position);
    }
}
